'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  router.post('/login', controller.user.login);
  router.post('/register', controller.user.register);
  router.get('/refresh', controller.user.refresh); // 无痛刷新
  // 20分钟过期  用户还在操作 刷新token
  // 获取商品列表
  router.get('/shop', controller.shop.getShopList)
  router.get('/shop/:id', controller.shop.getShopDetail)
  // 加入购物车
  router.post('/cart', middleware.auth(), controller.shop.addToCart)
  // 获取购物车列表
  router.get('/cart', middleware.auth(), controller.shop.getCartList)
  // 购物车商品数量修改
  router.put('/cart', middleware.auth(), controller.shop.setCartCount)
  // 删除购物车商品
  router.delete('/cart/:id', middleware.auth(), controller.shop.delCartById)
  // 上传图片/头像/封面
  router.post('/tools/saveavatar', middleware.error(), controller.article.saveAvatar);
};